<?php
/*
 +-----------------------------------------------
 |输入工具类--Input.Utils.php
 +-----------------------------------------------
 | Auth: dark2light@qq.com
 | Date: 2016.11.10
 +-----------------------------------------------
 |Main: 提供一个简单的输入防护
 +-----------------------------------------------
*/
namespace Utils;

class InputUtils
{
    public static function issetOrDft($strMethod, $dft = null)
    {
        list($method, $input) = explode('.', $strMethod);
        switch ($method) {
            case 'post':
                $method = &$_POST;
                break;
            case 'get':
                $method = &$_GET;
                break;
        }
        if (!empty($method[$input])) {
            return $method[$input];
        } else {
            return $dft;
        }
    }
    public static function issetOrFail($method, $input)
    {
        switch ($method) {
            case 'post':
                $method = &$_POST;
                break;
            case 'get':
                $method = &$_GET;
                break;
        }
        if (is_array($input)) {
            foreach ($input as $item) {
                if (@is_null($method[$item])) {
                    throw new \Exception("缺少必要参数：" . $item);
                }
                $paramList[] = $method[$item];
            }
        } else {
            throw new \Exception("参数以数组形式传入");
        }
        return $paramList;
    }
    public static function  parseParm()
    {
        //todo：参数解析
    }
    public static function dd($var)
    {
        echo "<pre>";
        var_dump($var);
    }
}
